﻿package plugin.ems.handler
{
    import cmd.*;
    import com.core.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import flash.geom.*;
    import flash.utils.*;
    import pluginfw.nio.*;
    import pluginfw.nio.imsg.*;
    import view.*;
    import view.message.*;

    public class EMSHandler extends Object implements IGroupHandler
    {

        public function EMSHandler()
        {
            return;
        }// end function

        public function dealSimpleMessage(param1:ISimpleMessage) : void
        {
            var _loc_2:Object = null;
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            var _loc_5:Object = null;
            switch(param1.getCmd())
            {
                case CMDEms.GetMyEmsInfo:
                {
                    _loc_2 = param1.getParam();
                    ModelProxy.change("data", "ems", _loc_2);
                    ModelProxy.change("ems", "getMyEmsInfo", _loc_2);
                    break;
                }
                case CMDEms.EMSFail:
                {
                    ModelProxy.change("data", "ems", null);
                    _loc_2 = param1.getParam();
                    ModelProxy.change("ems", "EMSFail", _loc_2);
                    DialogMgr.instance.open(AppDialog.EMS_FAIL, {type:0, param:_loc_2});
                    break;
                }
                case CMDEms.GetNewEms:
                {
                    _loc_2 = param1.getParam();
                    _loc_3 = ModelProxy.getValue("data", "ems");
                    if (_loc_3)
                    {
                        _loc_3[0] = _loc_2[0];
                        _loc_3[1] = false;
                    }
                    else
                    {
                        ModelProxy.change("data", "ems", [_loc_2[0], false, 0]);
                    }
                    ModelProxy.change("ems", "newEMS", _loc_2);
                    break;
                }
                case CMDEms.CompleteEms:
                {
                    _loc_2 = param1.getParam();
                    _loc_4 = UserData.getOnlineData();
                    _loc_4.ems = _loc_2[3];
                    ModelProxy.change("data", "ems", null);
                    ModelProxy.change("ems", "completeEms", _loc_2);
                    Alert2.show("<p align=\'center\'><font color=\'" + MColor.Newstr7 + "\' size=\'14\'>护送完成</font>\n获得经验：" + _loc_2[1] + "\n" + "绑定金币：" + _loc_2[2] + "</p>", "", ["确定"], null, null, true, false, false);
                    _loc_5 = UserData.getOnlineData();
                    ModelProxy.change("tasktrack", "getonline", _loc_5);
                    ModelProxy.change("plugin", "close", "npcdialog");
                    break;
                }
                case CMDEms.StartEms:
                {
                    _loc_2 = param1.getParam();
                    _loc_3 = ModelProxy.getValue("data", "ems");
                    if (_loc_3)
                    {
                        _loc_3[0] = _loc_2[0];
                        _loc_3[1] = true;
                        _loc_3[2] = _loc_2[2];
                    }
                    else
                    {
                        ModelProxy.change("data", "ems", [_loc_2[0], true, _loc_2[1]]);
                    }
                    _loc_4 = UserData.getOnlineData();
                    _loc_4.ems = _loc_2[1];
                    ModelProxy.change("tasktrack", "getonline", _loc_4);
                    ModelProxy.change("ems", "startEms", _loc_2);
                    break;
                }
                case CMDEms.EMSState:
                {
                    _loc_2 = param1.getParam();
                    ModelProxy.change("data", "ems", _loc_2);
                    ModelProxy.change("ems", "getMyEmsInfo", _loc_2);
                    break;
                }
                case 0:
                {
                    ModelProxy.change("movetips", "error", param1.getParam());
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function dealBufferMessage(param1:IBufferMessage) : void
        {
            var _loc_5:int = 0;
            var _loc_2:* = new Object();
            var _loc_3:* = new Input(null);
            var _loc_4:* = param1.getBody();
            param1.getBody().position = 0;
            _loc_3.setBytes(_loc_4);
            switch(param1.getCmd())
            {
                case CMDEms.EmsSuccess:
                {
                    _loc_5 = int((GlobalLayer.instance.root.stageWidth - 700) / 2);
                    ModelProxy.change("plugin", "open", {target:"npcdialog", point:new Point(GlobalLayer.instance.root.stageWidth / 2, GlobalLayer.instance.root.stageHeight / 2 - 120), top:new Point(_loc_5, 100), data:{npcid:1100, type:"ems"}});
                    ModelProxy.change("mainuiInstance", "emsFinished", null);
                    break;
                }
                case CMDEms.ResKillBiaoSuccessMessage:
                {
                    _loc_2.result = _loc_3.readByte();
                    ModelProxy.change("mainui", "showNbFly", {type:2, id:_loc_2.result});
                    break;
                }
                case CMDEms.ResChangeMyBiaoMessge:
                {
                    _loc_2.hp = _loc_3.readVarInt(false);
                    _loc_2.state = _loc_3.readByte();
                    ModelProxy.change("mainuiInstance", "emsFuckingState", _loc_2);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function dealProxyMessage(param1:IProxyMessage) : void
        {
            return;
        }// end function

    }
}
